import Vue from 'vue'
import Router from 'vue-router'

import Login from '../src/views/Login'
import Home from './views/Home'
import Main from './views/main/Main.vue'
import Basic from './views/main/child/Info/Basic_info'
import Account from './views/main/child/Info/Account_info'
import Cadre from './views/main/child/Info/Cadre_info'
import Group from './views/main/child/Info/Group_info'
import House from './views/main/child/Info/House_info'
import Job from './views/main/child/Info/Job_info'
import Org from './views/main/child/Info/Org_dev_info'
import Party from './views/main/child/Info/Party_info'
import SubsidyType from './views/main/child/Info/Subsidy_type'
import SubsidyInfo from './views/main/child/Info/Subsidy_info'
import Village from './views/main/child/Info/Village_info'

import Resource from './views/main/child/Capital/Resource'
import Assets from './views/main/child/Capital/Assets'
import Funds from './views/main/child/Capital/Funds'
import Construction from './views/main/child/Capital/Construction'
import Finan_manage from './views/main/child/Capital/Finan_manage'

import Policy from './views/main/child/Release/Policy'
import Legal from './views/main/child/Release/Legal'
import Village_announ from './views/main/child/Release/Village_announ'
import Village_meeting from './views/main/child/Release/Village_meeting'
import Edu_info from './views/main/child/Release/Edu_info'
import Org_act from './views/main/child/Release/Org_act'
import Village_act from './views/main/child/Release/Village_act'
import Village_plan from './views/main/child/Release/Village_plan'

//Admin
import Admin from './views/main/child/Admin/Admin'

import To_be_processed from './views/main/child/Feedback/To_be_processed'
import Processed from './views/main/child/Feedback/Processed'
import Upward from './views/main/child/Feedback/Upward'

//Log
import Log from './views/main/child/Log/Log'

//view


Vue.use(Router)

const router =  new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: Login,
      meta: {
        isPublic: true
      }
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      children: [
        {
          path: '/',
          name: 'main',
          component: Main,
          children: [
            //info
            {
              path: '/',
              redirect: '/info/basic'
            },
            {
              path: '/info',
              redirect: '/info/basic'
            },
            {
              path: '/info/basic',
              name: 'basic',
              component: Basic
            },
            {
              path: '/info/account',
              name: 'account',
              component: Account
            },
            {
              path: '/info/cadre',
              name: 'cadre',
              component: Cadre
            },
            {
              path: '/info/group',
              name: 'group',
              component: Group
            },
            {
              path: '/info/house',
              name: 'house',
              component: House
            },
            {
              path: '/info/job',
              name: 'job',
              component: Job
            },
            {
              path: '/info/org',
              name: 'org',
              component: Org
            },
            {
              path: '/info/party',
              name: 'party',
              component: Party
            },
            {
              path: '/info/subsidy-type',
              name: 'subsidyType',
              component: SubsidyType
            },
            {
              path: '/info/subsidy-info',
              name: 'subsidyInfo',
              component: SubsidyInfo
            },
            {
              path: '/info/village',
              name: 'village',
              component: Village
            },
            //capital
    
            {
              path: '/caption',
              redirect: '/caption/resource'
            },
            {
              path: '/caption/resource',
              name: 'resource',
              component: Resource
            },
            {
              path: '/caption/assets',
              name: 'assets',
              component: Assets
            },
            {
              path: '/caption/funds',
              name: 'funds',
              component: Funds
            },
            {
              path: '/caption/construction',
              name: 'construction',
              component: Construction
            },
            {
              path: '/caption/finan',
              name: 'finan',
              component: Finan_manage
            },
            //Release
    
    
            {
              path: '/release',
              redirect: '/release'
            },
            {
              path: '/release/policy',
              name: 'policy',
              component: Policy
            },
            {
              path: '/release/legal',
              name: 'legal',
              component: Legal
            },
            {
              path: '/release/announ',
              name: 'village_announ',
              component: Village_announ
            },
            {
              path: '/release/meeting',
              name: 'village_meeting',
              component: Village_meeting
            },
            {
              path: '/release/edu',
              name: 'edu_info',
              component: Edu_info
            },
            {
              path: '/release/org-act',
              name: 'org_act',
              component: Org_act
            },
            {
              path: '/release/act',
              name: 'village_act',
              component: Village_act
            },
            {
              path: '/release/plan',
              name: 'village_plan',
              component: Village_plan
            },
    
            //Admin
            {
              path: '/admin',
              name: 'admin',
              component: Admin
            },
    
            //Feedback
            {
              path: '/feedback',
              redirect: '/feedback/to-processed'
            },
            {
              path: '/feedback/to-processed',
              name: 'to-processed',
              component: To_be_processed
            },
            {
              path: '/feedback/processed',
              name: 'processed',
              component: Processed
            },
            {
              path: '/feedback/upward',
              name: 'upward',
              component: Upward
            },
    
            //Log
            {
              path: '/log',
              name: 'log',
              component: Log
            }
          ]
        }
      ]
    },
    
  ]
})

router.beforeEach((to, form, next) => {
  // if(!to.meta.isPublic && !localStorage.admin){
  //   return next('/login')
  // }
  if(!to.meta.isPublic && !localStorage.admin){
    return next('/login')
  }
  next()
})

export default router